package cn.idongjia.video;

import com.alibaba.dubbo.common.utils.StringUtils;

public class Utils {

    public static String getRandomName(String suffix) {
        long time = System.currentTimeMillis();
        long temp = Math.round(Math.random() * 8999 + 1000);
        return String.format("%d%d%s", time, temp, suffix);

    }

    public static String getFileDir(String addr) {
        if (StringUtils.isNotEmpty(addr)) {
            addr=addr.substring(addr.lastIndexOf(".com")+4, addr.lastIndexOf("/")+1);
            if(addr.length()>1){
                return addr.substring(0,addr.lastIndexOf("/"));
            }
            return addr;
        }
        return "";
    }

    public static String getFileName(String addr) {
        if (StringUtils.isNotEmpty(addr)) {
            return addr.substring(addr.lastIndexOf("/") + 1);
        }
        return "";
    }
   public static String  getVideoUrl(String addr){
       if(StringUtils.isNotEmpty(addr)){
           return addr.substring(0,addr.lastIndexOf(".com")+4);
       }
       return "";
   }
    public static void main(String[] args){
        String  addr="http://dongjiaapp.file.alimmdn.com/69531b3e-1e11-4d75-8af5-6ca6890a4455";
        System.out.println(getVideoUrl(addr));
        System.out.println(getFileDir(addr));
        System.out.println(getFileName(addr));
    }
}
